package com.taotao.manage.controller;

import com.taotao.common.pojo.EasyUIDataGridResult;
import com.taotao.common.service.RedisService;
import com.taotao.manage.pojo.Content;
import com.taotao.manage.pojo.Item;
import com.taotao.manage.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.JedisCluster;

@RestController
@RequestMapping("/content")
public class ContentController {
    @Autowired
    private ContentService contentService;

    @Autowired
    private RedisService redisService;

    private static String REDIS_BIG_AD_KEY="bigAdData";
    /**
     * 根据内容Id分页查询内容列表
     */
    @RequestMapping(method = RequestMethod.GET)
    public EasyUIDataGridResult queryContentListByCategoryId(@RequestParam(value = "categoryId", defaultValue = "0") Long categoryId, Integer page, Integer rows) {
        return contentService.queryContentListByCategoryId(categoryId, page, rows);
    }
    /**
     * 新增内容
     */
    @RequestMapping(method = RequestMethod.POST)
    public void saveContent(Content content){
        contentService.saveSelective(content);
        redisService.del(REDIS_BIG_AD_KEY);
    }
    /**
     * 更新内容
     */
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    public void updateContent(Content content){
        contentService.updateSelective(content);
        redisService.del(REDIS_BIG_AD_KEY);
    }
    /**
     * 删除内容
     */
    @RequestMapping(value = "/delete")
    public void deleteContent(Long[] ids) {
        contentService.deleteByIds(ids);
        redisService.del(REDIS_BIG_AD_KEY);
    }
}
